// logs.js
const util = require('../../utils/util.js')
import { ml_showToast, ml_Toast } from '../../utils/asyncWX.js'
Page({
  data: {
    modellist:null,
    nowtime:null,
    content:''
  },
  content(e){
    console.log(e.detail.value)
    this.setData({content:e.detail.value});
  },

  updelect(){
    if(!this.data.modellist.type){
      wx.showToast({
        icon:'none',
        title: '这个位置已经没有样品了哦~',
      })
    }else{
      wx.cloud.callFunction({name:'delectdata',data:{'id':this.data.modellist.login_inf._id}}).then(res=>{
        console.log(res)
        if(res.result == 200){
          ml_showToast('已成功');
          wx.navigateBack({
            delta: 1,
          })
        }else{
          ml_Toast('取出失败，请重新尝试！');
        }
      }).catch(res=>{
        ml_Toast('取出失败，请重新尝试！');
      })
    }
  },
  giveru(){
    if(this.data.modellist.type){
      wx.showToast({
        icon:'none',
        title: '请先取出后再放入',
      })
    }else{
      if(this.data.content == ''){
        ml_Toast('请填写样品信息');
      }else{
        wx.cloud.database().collection('login_infs').add({data:{
          chiose_low:this.data.modellist.low,
          chiose_row:this.data.modellist.row,
          treach:this.data.modellist.treach,
          login_name:this.data.content,
          srting_time:this.data.nowtime
        }}).then(res=>{
          console.log(res);
          ml_showToast('放入成功！');
          wx.navigateBack({
            delta: 1,
          })
        })
      }
    }
  },
  gettime(){
    var time = new Date();
    var dates = time.getFullYear()+'-'+(time.getMonth()+1)+'-'+time.getDate()
    let times = time.toLocaleTimeString('chinese', { hour12: false });
    this.setData({nowtime:dates +' '+ times})
  },
  onLoad(opt) {
    this.gettime();
    let datas = JSON.parse(opt.item);
    this.setData({modellist:datas});
    console.log(datas);
  }
})
